<form action="index.php?top=page&option=com_frquestion" method="post" name="adminFormSearch" id="adminFormSearch">
<!-- LEFT -->
 <?php echo $this->loadTemplate('search','default') ?>
 <input type="hidden" name="task" value="search" />
 <!-- END LEFT -->
</form>
<form action="index.php?top=page&option=com_frquestion" method="post" name="adminForm" id="adminForm"> 
 <!-- CONTENT -->
 <div id="jm-content">   
     <h3 class="jm-title">
        <label class="jm_name">質問集</label>
        <span class="float-right"><button style="margin-top: 2px;" href="index.php?top=page&option=com_frquestion&task=defaut" >戻る</button></span></h3>
        
     <div id="page_content">   
        
        <div class="div_header">
            <p class="div_title"><?php echo $this->row->SERQ_TITLE; ?></p>
            <div class="intro">
                <?php echo $this->row->SERQ_DESCRIPTION; ?>                                        
            </div>                
        </div>
        <div class="div_img">
                        
            <?php
                if(!empty($this->row->SERQ_IMG)){
                    $path = "uploads/images/com_questionare/".$this->row->SERQ_IMG;
                    if(file_exists($path)){ 
                        echo '<td><img src="'.$path.'" style="width: 200px;" /></td>';
                    }else{
                        
                    }
                }else{
                    
                }
            ?>                
        </div>
        <div class="cls"></div>
        
       <!-- CONTENT QUESTION -->
        
        <div id="ques_content">

            <div class="button_start">
                <!-- START: スタート -->
                <input type="button" onclick="showQues();" class="button" id="btnstart" style="cursor: pointer; min-width: 80px; min-height: 30px;" value="スタート" />
                <div class="intro_page"><?php echo $this->list_question[0]->PAGQ_TITLE; ?></div>
                <div class="content_intro"><?php echo $this->list_question[0]->PAGQ_DESCRIPTION; ?></div>
                
            </div>  
        </div>
        
        <!-- END CONTENT -->
        <input type="hidden" name="index" id="index" value="0" />
        <input type="hidden" name="list_page" id="list_page" value="<?php echo $this->list_page; ?>" />
        <input type="hidden" name="serq_code" id="serq_code" value="<?php echo $this->row->SERQ_CODE; ?>" />
        
        <input type="hidden" name="task" value="ques" />
        
    </div>
    
 </div>
 </form>
<script>
    Joomla.submitbutton = function(task){
        if(task == 'search'){
            Joomla.submitform(task, document.getElementById('adminFormSearch'));
            return false;
        }
     }
     
     
    /* ajax: load list question when click start button */
    function showQues(){
        
		var serq_code = jq("#serq_code").val();
        var list_page = jq("#list_page").val();
        var index = jq("#index").val();
        
		var url = "index.php?option=com_frquestion&task=showQuestion&serq_code="+serq_code+"&list_page="+list_page+"&index="+index;
        
        jq.get(url, function(data) {
              jq('#ques_content').html(data);
        });
            	
	}
    
    /* ajax: load list question when click next button */
    function showQuesNext(serq_code,index,sess_code){
        /* check answer question */
        var flag = true;
        jq('.input_check').each(function(){
            if(jq(this).val() == ''){
                /* message: hay tra loi nhung cau hoi can thiet. */
                alert("必須の質問をご回答ください。");
                flag = false;
                return;                
            }
        });
        
        if(!flag) return false;
                        
        /* get data */
        var kq = '';
        jq('.checkbox_ans').each(function() {
                        
            if(jq(this).is(':checked')){
                id = jq(this).val();
                kq += "."+id;
                
            }
        });
        
        jq('.radio_ans').each(function() {
                        
            if(jq(this).is(':checked')){
                id = jq(this).val();
                kq += "."+id;
                
            }
        });
        
        
        jq('.text_ans').each(function() {
            if(jq(this).val() == ''){
                check = jq(this).attr('check');
                if(check == 1){
                    /* message: hay tra loi nhung cau hoi can thiet. */
                    alert("必須の質問をご回答ください。");
                    flag = false;
                    return;
                }
            }
            if(jq(this).val() != ''){
                val = jq(this).val();
                //encoding value of element textarea
                if(val != ''){
                    val = encodeURI(val);
                    for(var i=0;i<val.length;i++){
                        if(val[i] == "%"){
                            val = val.replace("%","-");
                        }
                    }
                    
                }
                //end endcoding
                
                id = jq(this).attr('id');
                val = id+"_"+val+"_3";
                kq += "."+val;
                
            }
        });
        
        if(!flag) return false;
                
        /*load ajax*/
        var list_page = jq("#list_page").val();
		var url = "index.php?option=com_frquestion&task=showQuesNext&serq_code="+serq_code+"&sess_code="+sess_code+"&list_page="+list_page+"&index="+index+"&result="+kq;
        
        jq.get(url, function(data) {
              jq('#ques_content').html(data);
              
        });
                    	
	}
    
     /* ajax: load list question when click prev button */
    function showQuesPrev(serq_code,index,sess_code){
                        
        /* get data */
        var kq = '';
        jq('.checkbox_ans').each(function() {
            
            if(jq(this).is(':checked')){
                id = jq(this).val();
                kq += "."+id;
                
            }
        });
        
        jq('.radio_ans').each(function() {
            
            if(jq(this).is(':checked')){
                id = jq(this).val();
                kq += "."+id;
                
            }
        });
        
        jq('.text_ans').each(function() {
            
            if(jq(this).val() != ''){
                val = jq(this).val();
                //encoding value of element textarea
                if(val != ''){
                    val = encodeURI(val);
                    for(var i=0;i<val.length;i++){
                        if(val[i] == "%"){
                            val = val.replace("%","-");
                        }
                    }
                    
                }
                //end endcoding
                
                id = jq(this).attr('id');
                val = id+"_"+val+"_3";
                kq += "."+val;
                
            }
        });
        
                
        /* load ajax */
        var list_page = jq("#list_page").val();
		var url = "index.php?option=com_frquestion&task=showQuesPrev&serq_code="+serq_code+"&sess_code="+sess_code+"&list_page="+list_page+"&index="+index+"&result="+kq;
        
        jq.get(url, function(data) {
              jq('#ques_content').html(data);
              
        });            	
	}
    
    /* ajax: load list question when click end button */
    function showQuesEnd(serq_code,sess_code){
        
        /* check answer question */
        var flag = true;
        jq('.input_check').each(function(){
            if(jq(this).val() == ''){
                /* message: hay tra loi nhung cau hoi can thiet. */
                alert("必須の質問をご回答ください。");
                flag = false;
                return;                
            }
        });
        
        if(!flag) return false;
                
        /* get data */
        var kq = '';
        jq('.checkbox_ans').each(function() {
                        
            if(jq(this).is(':checked')){
                id = jq(this).val();
                kq += "."+id;
                
            }
        });
        
        jq('.radio_ans').each(function() {
            
            if(jq(this).is(':checked')){
                id = jq(this).val();
                kq += "."+id;
                
            }
        });
        
        jq('.text_ans').each(function() {
            
            if(jq(this).val() == ''){
                check = jq(this).attr('check');
                if(check == 1){
                    /* message: hay tra loi nhung cau hoi can thiet. */
                    alert("必須の質問をご回答ください。");
                    flag = false;
                    return;
                }
            }
            
            if(jq(this).val() != ''){
                val = jq(this).val();
                
                //encoding value of element textarea
                if(val != ''){
                    val = encodeURI(val);
                    for(var i=0;i<val.length;i++){
                        if(val[i] == "%"){
                            val = val.replace("%","-");
                        }
                    }
                    
                }
                //end endcoding
                
                id = jq(this).attr('id');
                val = id+"_"+val+"_3";
                kq += "."+val;
                
            }
        });
        
        if(!flag) return false;
                
        /*load ajax*/
		var url = "index.php?option=com_frquestion&task=showQuesEnd&serq_code="+serq_code+"&sess_code="+sess_code+"&result="+kq;
        
        jq.get(url, function(data) {
              jq('#page_content').html(data);
              
        });
            	
	}
</script>


                           